﻿namespace System.NETool;

public static class ConsoleEx
{
    /// <summary>
    /// 使用指定状态颜色写入一行文本
    /// </summary>
    /// <param name="this">要写入的文本</param>
    /// <param name="status">状态，true 为绿色，false 为红色</param>
    public static void WriteLine(object @this, bool status)
    {
        WriteLine(@this, status ? ConsoleColor.Green : ConsoleColor.Red);
    }

    /// <summary>
    /// 使用指定颜色写入一行文本
    /// </summary>
    /// <param name="this">要写入的文本</param>
    /// <param name="color">文本颜色</param>
    public static void WriteLine(object @this, ConsoleColor color)
    {
        Console.ForegroundColor = color;
        Console.WriteLine(@this == null ? "null" : @this.ToString());
        Console.ResetColor();
    }

    public static void WriteLine(params object[] @this)
    {
        if (@this.Length == 0) return;
        if (@this.Length == 1)
        {
            Console.WriteLine(@this[0] == null ? "null" : @this[0].ToString());
            return;
        }

        ValueStringBuilder sb = new(1024);
        for (int i = 0; i < @this.Length - 1; i++)
        {
            sb.Append(@this[i] == null ? "null" : @this[i].ToString());
            sb.Append(", ");
        }

        sb.Append(@this[^1] == null ? "null" : @this[^1].ToString());
        Console.WriteLine(sb.ToString());
    }
}
